package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.UserPermissionMapper;
import com.example.servicea.entity.UserPermissionEntity;
import com.example.servicea.service.UserPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("userPermissionServiceImpl")
public class UserPermissionServiceImpl implements UserPermissionService {
	@Autowired
	private UserPermissionMapper userPermissionMapper;
    @Override
    public boolean insert(UserPermissionEntity obj){
        return SqlHelper.retBool(userPermissionMapper.insert(obj));
    }
    @Override
    public List<UserPermissionEntity> selectList(UserPermissionEntity userPermission){
        EntityWrapper<UserPermissionEntity> query = new EntityWrapper<UserPermissionEntity>();
		return userPermissionMapper.selectList(query);
	}

    @Override
    public Page selectPage(UserPermissionEntity userPermission, String page, String limit){
        EntityWrapper<UserPermissionEntity> query = new EntityWrapper<UserPermissionEntity>();
        List<UserPermissionEntity> list = userPermissionMapper.selectPage(
                new Page<UserPermissionEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = userPermissionMapper.selectCount(query);
        Page UserPermissionEntityPage = new Page();
        return UserPermissionEntityPage;
	}
    @Override
    public int selectCount(UserPermissionEntity userPermission){
        EntityWrapper<UserPermissionEntity> query = new EntityWrapper<UserPermissionEntity>();
        return userPermissionMapper.selectCount(query);
	}

    @Override
    public UserPermissionEntity selectOne(UserPermissionEntity userPermission){
        return userPermissionMapper.selectOne(new UserPermissionEntity());
	}

    @Override
    public UserPermissionEntity selectById(String id){
        return userPermissionMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(UserPermissionEntity userPermission){
        return SqlHelper.retBool(userPermissionMapper.updateById(userPermission));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(userPermissionMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(userPermissionMapper.deleteBatchIds(list));
	}
	
}
